home *** CD-ROM | disk | FTP | other *** search
- Path: hopper.acm.org!news
- From: varnk@e62.diebold.com (Ken Varn)
- Newsgroups: comp.lang.c
- Subject: Re: Beginer C please help me
- Date: 21 Mar 1996 15:19:32 GMT
- Organization: Diebold
- Message-ID: <4irs25$c6m@hopper.acm.org>
- References: <DoLCFx.B7x.0.bloor@torfree.net>
- NNTP-Posting-Host: 199.218.232.47
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <DoLCFx.B7x.0.bloor@torfree.net>, bz786@torfree.net says...
- />
- />This may be a stupid mistake but "please help" me.
- />Thank you very much.
- />
- />#include <stdio.h>
- />#include <math.h>
- />main ()
- />{
- />float n;
- />n=(9/5);
- />printf ("n= %1.3f\n", n);
- />}
- />I have complied and run the programme & I got the answer n=1.000
- />but Iam supposed to get answer 1.8.
- />Why I got this answer?
-
- Your modifiers on the %f are incorrect. The usage is
- minimum_width.precision. In other words, you are telling printf to print the
- number with a minimum of 1 wide with a precision of 3. Since printf does
- rounding, your result is 1.000. To correct this, use %3.1f. This tells
- printf to print a minimum of 3 characters with a precision of 1.
-
-